from rest_framework import serializers
from .models import Course,Stage,Chapter,Section


class CourseSerializer(serializers.ModelSerializer):
    '''课程分类序列化器'''
    stages_count = serializers.IntegerField()
    chapter_count = serializers.IntegerField()
    section_count = serializers.IntegerField()
    class Meta:
        model = Course
        fields = '__all__'

class StageSerializer(serializers.ModelSerializer):
    '''课程阶段序列化器'''
    class Meta:
        model = Stage
        fields = '__all__'

class ChapterSerializer(serializers.ModelSerializer):
    '''课程章节序列化器'''
    class Meta:
        model = Chapter
        fields = '__all__'

class SectionSerializer(serializers.ModelSerializer):
    '''章节小节序列化器'''
    class Meta:
        model = Section
        fields = '__all__'

class ChapterDetailSerializer(serializers.ModelSerializer):
    '''课程章节详情序列化器'''#名字要和数据库中的外键名字一致
    section = SectionSerializer(many=True,read_only=True)

    class Meta:
        model = Chapter
        fields = '__all__'

class StageDetailSerializer(serializers.ModelSerializer):
    '''课程阶段详情序列化器'''
    chapter = ChapterDetailSerializer(many=True,read_only=True)

    class Meta:
        model = Stage
        fields = '__all__'